package com.example.worklab.animation.utils

import android.view.ViewGroup.LayoutParams
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.updateLayoutParams

object UnReadMsgUtils {
    fun show(numView: AppCompatTextView?, num: Int) {
        if (numView == null) {
            return
        }
        val dm = numView.resources.displayMetrics

        when (num) {
            in 1..9 -> {
                numView.updateLayoutParams<LayoutParams> {
                    width = (25 * dm.density).toInt()
                }
                numView.text = "$num"
            }

            in 10..99 -> {
                numView.updateLayoutParams<LayoutParams> {
                    width = LayoutParams.WRAP_CONTENT
                }
                val hPadding = (7 * dm.density).toInt()
                numView.setPadding(hPadding, 0, hPadding, 0)
                numView.text = "$num"
            }

            else -> {
                numView.updateLayoutParams<LayoutParams> {
                    width = LayoutParams.WRAP_CONTENT
                }
                val hPadding = (7 * dm.density).toInt()
                numView.setPadding(hPadding, 0, hPadding, 0)
                numView.text = "99+"
            }
        }
    }
}